package com.jtlrm.ckd.mvp.view.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.jtlrm.ckd.entity.event.RegisterFinishMessage;
import com.jtlrm.ckd.util.EventBusUtil;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class SettingPasswordActivity extends RebuilPasswordActivity {

    String phone;

    public static void goSetting(Context context, String phone) {
        Intent intent = new Intent(context, SettingPasswordActivity.class);
        intent.putExtra("phone", phone);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        phone = getIntent().getStringExtra("phone");
        super.onCreate(savedInstanceState);
        EventBusUtil.register(this);
    }

    @Override
    protected String getTitleText() {
        return "设置密码";
    }

    @Override
    public void submit(View view) {
        if (passwordIsOk()) {
            CompleteInfoActivity.goActivity(context, passwordStr, phone);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(RegisterFinishMessage message) {
        if (message != null) {
            if (!context.isFinishing()){
                finish();
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBusUtil.unregister(this);
    }
}
